<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="推广员姓名" prop="name">
        <el-input v-model="queryParams.paramMap.name" placeholder="请输入推广员姓名" clearable
          style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="推广员手机号" prop="mobile">
        <el-input v-model="queryParams.paramMap.mobile" placeholder="请输入手机号" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderSn">
        <el-input v-model="queryParams.orderSn" placeholder="请输入订单编号" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="提现状态" prop="withdrawalStatus">
        <el-select v-model="queryParams.withdrawalStatus" placeholder="提现状态" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.popularize_withdrawal_status" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="申请提现时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:role:export']">导出</el-button>
      </el-col>
      -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="rextensionWorkerOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" prop="id" width="180" />
      <el-table-column label="推广员姓名" prop="name" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="推广员手机号" prop="mobile" :show-overflow-tooltip="true" width="120" />
      <el-table-column label="订单编号" prop="orderSn" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="客户编号" prop="businessCode" width="80" :show-overflow-tooltip="true" />
      <el-table-column label="支付金额" prop="flowPrice" width="80" />
      <el-table-column label="退款金额" prop="refundPrice" width="80" />
      <el-table-column label="订单状态" prop="orderStatus" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_order_status" :value="scope.row.orderStatus" />
        </template>
      </el-table-column>
      <el-table-column label="奖励金额" prop="rewardAmount" width="80" />
      <el-table-column label="提现状态" prop="withdrawalStatus" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.popularize_withdrawal_status" :value="scope.row.withdrawalStatus" />
        </template>
      </el-table-column>
      <el-table-column label="申请提现时间" align="center" prop="applyWithdrawalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyWithdrawalTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到账时间" align="center" prop="receivedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receivedTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleReview(scope.row)"
            v-show="scope.row.withdrawalStatus=='APPLIED'"
            v-hasPermi="['popularize:popularize:worder:order:withdrawalStatus:edit']">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 审核对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="title" :visible.sync="open" width="650px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单编号" prop="orderSn">
              <el-input v-model="form.orderSn" placeholder="请输入订单编号" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单状态" prop="orderStatus">
              <el-select v-model="form.orderStatus" placeholder="请选择订单状态" style="width: 200px">
                <el-option v-for="dict in dict.type.order_order_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="奖励金额" prop="rewardAmount">
              <el-input v-model="form.rewardAmount" placeholder="请输入奖励金额" style="width: 200px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提现状态" prop="withdrawalStatus">
              <el-select v-model="form.withdrawalStatus" placeholder="请选择提现状态" style="width: 200px">
                <el-option v-for="dict in dict.type.popularize_withdrawal_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listExtensionWorkerOrder, reviewExtensionWorkerOrder } from "@/api/popularize/extensionWorker";

export default {
  name: "ExtensionWorkerOrder",
  dicts: ["popularize_withdrawal_status", "order_order_status"],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 推广订单信息表格数据
      rextensionWorkerOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限",
        },
        {
          value: "2",
          label: "自定数据权限",
        },
        {
          value: "3",
          label: "本部门数据权限",
        },
        {
          value: "4",
          label: "本部门及以下数据权限",
        },
        {
          value: "5",
          label: "仅本人数据权限",
        },
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderSn: undefined,
        withdrawalStatus: undefined,
        paramMap:{
          name: undefined,
          mobile: undefined,
        },
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询推广员信息列表 */
    getList () {
      this.loading = true;
      listExtensionWorkerOrder(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.rextensionWorkerOrderList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope () {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: undefined,
        name: undefined,
        mobile: undefined,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.roleId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        "system/role/export",
        {
          ...this.queryParams,
        },
        `推广订单_${new Date().getTime()}.xlsx`
      );
    },
    handleReview(row){
      this.form = row
      this.title = "审核提现申请"
      this.open = true
    },
    submitForm(){
      let _this = this
      this.$modal.confirm('确认提交审核吗？').then(function () {
        reviewExtensionWorkerOrder(_this.form.extensionWorkerId, _this.form.id, _this.form).then(res=>{
          _this.$modal.msgSuccess("审核成功");
          _this.open = false
          _this.getList()
        });
      }).catch(function () {
      });
    },
  },
};
</script>
